
package com.usersmodule.servlet;
import com.usersmodule.bean.TbUserActions;
import com.usersmodule.dao.TbUserActionsDAO;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import util.*;

public class TbUserActionsServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        if("add".equals(method)){
        String userActionName=request.getParameter("userActionName");
        String userActionMemo=request.getParameter("userActionMemo");
            if(new TbUserActionsDAO().add(new TbUserActions(userActionName,userActionMemo))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
            goList(request, response);
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_UserActions", "UserAction", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
            goList(request, response);
        }
        if("edit".equals(method)){
        int userAction=Integer.parseInt(request.getParameter("userAction"));
        String userActionName=request.getParameter("userActionName");
        String userActionMemo=request.getParameter("userActionMemo");
        if(new TbUserActionsDAO().edit(new TbUserActions(userAction,userActionName,userActionMemo))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
            goList(request, response);
        }
        if ("list".equals(method)) goList(request, response);
        if ("listById".equals(method)) {
            request.getSession().setAttribute("tbUserActions",new TbUserActionsDAO().getTbUserActionsByUserAction(Integer.parseInt(request.getParameter("userAction"))));
            response.sendRedirect("UsersModule/TbUserActionsOperate.jsp");
    	}
        if("showadd".equals(method)){
            request.getSession().removeAttribute("tbUserActions");
            response.sendRedirect("UsersModule/TbUserActionsOperate.jsp");
        }
    }
    public void goList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	request.getSession(true).setAttribute("tbUserActionsList",new TbUserActionsDAO().getTbUserActionsAll());
        response.sendRedirect("UsersModule/TbUserActionsList.jsp");
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doGet
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doPost
}
